var fectureArray=new Array();
fectureArray=["请选择"];


function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,'');
  }//去掉空格

function chekedform() {
	
	if(trim(document.getElementById('title').value) == ''){
		alert('请填写资讯标题！');
		document.getElementById('title').focus();
		return false;
	}
	
	var ch_attr  ='';
	for( var i = 1;i < 4;i++){
		if( $('sort'+i).value != ''){
			if($('ch_flag').value == 0){
				alert('请选择完整栏目！');
				return false;
			}
			ch_attr += $('sort'+i).value + '|';	
		}
	}
  if(ch_attr == ''){
    alert('请选择栏目！');
    document.getElementById('sort1').focus();
	  return false;
  }
  
  $('ch_id_group').value = ch_attr;
	
	var str = CKEDITOR.instances.content.getData();
	str = str.replace('<br />','');
 	str = str.replace('<br>','');
 	str = trim(str);
  if(str == ''){
  	alert('请填写资讯内容!');
  	CKEDITOR.instances.content.focus();
		return false;
	}
  document.addForm.submit();
}

function modifyform() {
	
	if(trim(document.getElementById('title').value) == ''){
		alert('请填写资讯标题！');
		document.getElementById('title').focus();
		return false;
	}
	
	if(document.getElementById("ch_id_group").value == ''){
		var ch_attr  = '';
		for( var i = 1;i < 4;i++){
			if( $('sort'+i).value != ''){
				if($('ch_flag').value == 0){
					alert('请选择完整栏目！');
					return false;
				}
				ch_attr += $('sort'+i).value + '|';	
			}
		}
	  if(ch_attr == ''){
	    alert('请选择栏目！');
	    document.getElementById('sort1').focus();
		  return false;
	  }
	  $('ch_id_group').value = ch_attr;
	}
  
	
	var str = CKEDITOR.instances.content.getData();
	str = str.replace('<br />','');
 	str = str.replace('<br>','');
 	str = trim(str);
  if(str == ''){
  	alert('请填写资讯内容!');
  	CKEDITOR.instances.content.focus();
		return false;
	}
  document.addForm.submit();
}


function setSecondCh(val) {
	if(document.getElementById('sort1').value == ''){
		document.getElementById('sort2').style.display = 'none';
		document.getElementById('sort3').style.display = 'none';
		document.getElementById('sort1').value = '';
		document.getElementById('sort2').value = '';
		document.getElementById('sort3').value = '';
	}else{
		Ti_newschannelInfo.getClassByUpId(val, set_Sort2);
	}
}

function set_Sort2(map_data) {
	
	if (map_data != null) {
		Ti_newschannelInfo.checkSonById($('sort1').value,function(ret){
		 if(ret == '0'){
		 	$('ch_flag').value = '1';
		 }else{
		 	 	DWRUtil.removeAllOptions('sort2');
				DWRUtil.addOptions('sort2',fectureArray);
				DWRUtil.addOptions('sort2', map_data);
				var item = $('sort2').length;
				if (item == 0) {
					$('sort2').style.display = 'none';
					$('ch_flag').value = '1';
				} else {
					$('sort2').style.display = 'inline';
					$('ch_flag').value = '0';
				}
		 }
	 });
	}
}

function setTherdCh(val) {
	Ti_newschannelInfo.getClassByUpId( val, set_Sort3);
}
function set_Sort3(map_data) {
	if (map_data != null) {
		Ti_newschannelInfo.checkSonById($('sort2').value,function(ret){
		 if(ret == '0'){
		 	$('ch_flag').value = '1';
		 }else{
		 	 	DWRUtil.removeAllOptions('sort3');
				DWRUtil.addOptions('sort3',fectureArray);
				DWRUtil.addOptions('sort3', map_data);
				var item = $('sort3').length;
				if (item == 0) {
					$('sort3').style.display = 'none';
					$('ch_flag').value = '1';
				} else {
					$('sort3').style.display = 'inline';
					$('ch_flag').value = '0';
				}
		 }
	 });
	}
}

function setLastCh(){
	if($('sort3').value != ''){
		$('ch_flag').value = '1';
	}
}


function ChangeOrg(){
	document.getElementById('org1').style.display = 'none';
	document.getElementById('org2').style.display = 'inline';
	document.getElementById('ch_id_group').value = '';
}


function seacher(){
	document.indexForm.submit()
}
	



function setSecond_Ch(val) {
	if(document.getElementById('sort1').value == ''){
		document.getElementById('sort2').style.display = 'none';
		document.getElementById('sort3').style.display = 'none';
		document.getElementById('sort1').value = '';
		document.getElementById('sort2').value = '';
		document.getElementById('sort3').value = '';
	}else{
		Ti_newschannelInfo.getClassByUpId(val, setSort2);
	}
}

function setSort2(map_data) {
	
	if (map_data != null) {
		Ti_newschannelInfo.checkSonById($('sort1').value,function(ret){
		 if(ret == '0'){
		 }else{
		 	 	DWRUtil.removeAllOptions('sort2');
				DWRUtil.addOptions('sort2',fectureArray);
				DWRUtil.addOptions('sort2', map_data);
				var item = $('sort2').length;
				if (item == 0) {
					$('sort2').style.display = 'none';
				} else {
					$('sort2').style.display = 'inline';
				}
		 }
	 });
	}
}

function setTherd_Ch(val) {
	Ti_newschannelInfo.getClassByUpId( val, setSort3);
}
function setSort3(map_data) {
	if (map_data != null) {
		Ti_newschannelInfo.checkSonById($('sort2').value,function(ret){
		 if(ret == '0'){
		 }else{
		 	 	DWRUtil.removeAllOptions('sort3');
				DWRUtil.addOptions('sort3',fectureArray);
				DWRUtil.addOptions('sort3', map_data);
				var item = $('sort3').length;
				if (item == 0) {
					$('sort3').style.display = 'none';
				} else {
					$('sort3').style.display = 'inline';
				}
		 }
	 });
	}
}

function delIndexInfos( val ){
    var opr = document.getElementById(val+'_operating').value;
	var listsize = document.getElementById('listsize').value;
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	if(pkid_string == ''){
		alert('请至少选择一条!');
		return false;
	}else{
		if(opr == '-'){
			document.getElementById('pkid').value = pkid_string;
			document.indexForm.action='/doTradeReg.do';
			if(window.confirm('确认删除吗?')){
				document.indexForm.submit();
			}
		}
		if( opr == '0' || opr == '2'){
			document.getElementById('pkid').value = pkid_string;
			document.getElementById('bpm_id').value = '1894';
			document.getElementById('state_code').value = opr;
			document.indexForm.action='/doTradeReg.do';
			if(window.confirm('确认此操作吗?')){
				document.indexForm.submit();
			}
		}
	}
	
}


function deleteOneInfo(pkid,bpm_id,sel){
    
	 if(window.confirm('确认删除？')){
	  window.location.href='/doTradeReg.do?pkid='+pkid+'&bpm_id='+bpm_id;
 	}
}


function audit(){
	if(document.getElementById('state_code2').checked)
	{
	   if(document.getElementById('remark').value == ""){
	     alert('请输入不通过理由！');
		 return;
	   }
	}else{
	  document.getElementById('remark').value ='';
	}
	document.addForm.submit();
}
